home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / bc_pas_1.zip / MVOUT.ASM < prev    next >
Assembly Source File  |  1992-12-07  |  10KB  |  304 lines

  1.  
  2.         page    64,131
  3.     Title    MVOUT  --  Pro Audio Spectrum direct I/O
  4.  
  5. ;   /*\
  6. ;---|*|-------------------------====< MVOUT >====-------------------------
  7. ;---|*|
  8. ;---|*|  This module contains some code for supporting direct I/O to the PAS
  9. ;---|*|  where the hardware is write only. All calls reference the state
  10. ;---|*|  table to guarrantee proper I/O values.
  11. ;---|*|
  12. ;---|*|  Media Vision, Inc. Copyright (c) 1991,1992. All Rights Reserved.
  13. ;---|*|
  14. ;   \*/
  15.  
  16.  
  17.     .xlist
  18.     include model.inc
  19.         include masm.inc
  20.     include state.inc
  21.     include common.inc
  22.     .list
  23.  
  24.     externADDR MVInitStatePtr    ; state table pointer stuff
  25.     externADDR mvGetHWVersion    ; find the board address...
  26.  
  27. if MODELSIZE eq 0
  28.     .code
  29. else
  30.     .data
  31. endif
  32.  
  33. ;
  34. ; The following label allows us to calculate an offset for the tables of
  35. ; addresses
  36. ;
  37. FirstDataByte   label   byte            ; !!!!!! must be the 1st entry in
  38. ;                    ; the data segmment!!!
  39. ;
  40. ; our first pass flag - set to -1 for first entry, will be zeroed out
  41. ;
  42. invmso_first    db    -1        ; -1 for first pass, to be zeroed out
  43.  
  44. ;
  45. ; Hardware Shadowing Table of Registers
  46. ;
  47.         public  shadowregtable
  48. shadowregtable    label    word
  49.     dw    SYSSPKRTMR        ; 00042h ; System Speaker Timer Address
  50.     dw    SYSTMRCTLR        ; 00043h ; System Timer Control Register
  51.     dw    SYSSPKRREG        ; 00061h ; System Speaker Register
  52.     dw    JOYSTICK        ; 00201h ; Joystick Register
  53.     dw    LFMADDR         ; 00388h ; Left  FM Synthesizer Address Register
  54.     dw    LFMDATA         ; 00389h ; Left  FM Synthesizer Data Register
  55.     dw    RFMADDR         ; 0038Ah ; Right FM Synthesizer Address Register
  56.     dw    RFMDATA         ; 0038Bh ; Right FM Synthesizer Data Register
  57.     dw    DFMADDR     ;AUXADDR; 00788h ; Dual  FM Synthesizer Address Register
  58.     dw    DFMDATA     ;AUXDATA; 00789h ; Dual  FM Synthesizer Data Register
  59.         dw      0                       ; 0078Ah ; reserved for future use
  60.     dw    0            ; 0078Bh ; reserved for future use
  61.         dw      AUDIOMIXR               ; 00B88h ; Audio Mixer Control Register
  62.     dw    INTRCTLRST        ; 00B89h ; Interrupt Status Register
  63.     dw    AUDIOFILT        ; 00B8Ah ; Audio Filter Control Register
  64.     dw    INTRCTLR        ; 00B8Bh ; Interrupt Control Register
  65.     dw    PCMDATA         ; 00F88h ; PCM data I/O register
  66.     dw    0            ; 00F89h ; reserved for future use
  67.     dw    CROSSCHANNEL        ; 00F8Ah ; Cross Channel
  68.     dw    0            ; 00F8Bh ; reserved for future use
  69.         dw      SAMPLERATE              ; 01388h ; Sample Rate Timer Register
  70.     dw    SAMPLECNT        ; 01389h ; Sample Count Register
  71.     dw    SPKRTMR         ; 0138Ah ; Local Speaker Timer Address
  72.     dw    TMRCTLR         ; 0138Bh ; Local Timer Control Register
  73.     dw    MDIRQVECT        ; 01788H ; MIDI IRQ Vector Register
  74.     dw    MDSYSCTLR        ; 01789H ; MIDI System Control Register
  75.     dw    MDSYSSTAT        ; 0178AH ; MIDI IRQ Status Register
  76.     dw    MDIRQCLR        ; 0178BH ; MIDI IRQ Clear Register
  77.     dw    MDGROUP4        ; 01B88H ; MIDI Group #4 Register
  78.     dw    MDGROUP5        ; 01B89H ; MIDI Group #5 Register
  79.     dw    MDGROUP6        ; 01B8AH ; MIDI Group #6 Register
  80.     dw    MDGROUP7        ; 01B8BH ; MIDI Group #7 Register
  81.  
  82. SHADOWTABLELEN  equ     28              ; 28 entries in the shadow data table
  83.  
  84. ;
  85. ; Storage Locations for the data
  86. ;
  87.     public    shadowdatatable
  88. shadowdatatable label    word
  89.     dw    offset _sysspkrtmr    ; 00042h ; System Speaker Timer Address
  90.     dw    offset _systmrctlr    ; 00043h ; System Timer Control Register
  91.     dw    offset _sysspkrreg    ; 00061h ; System Speaker Register
  92.     dw    offset _joystick    ; 00201h ; Joystick Register
  93.     dw    offset _lfmaddr     ; 00388h ; Left  FM Synthesizer Address Register
  94.     dw    offset _lfmdata     ; 00389h ; Left  FM Synthesizer Data Register
  95.     dw    offset _rfmaddr     ; 0038Ah ; Right FM Synthesizer Address Register
  96.     dw    offset _rfmdata     ; 0038Bh ; Right FM Synthesizer Data Register
  97.     dw    offset _dfmaddr     ; 00788h ; Dual  FM Synthesizer Address Register
  98.     dw    offset _dfmdata     ; 00789h ; Dual  FM Synthesizer Data Register
  99.     dw    0            ; 0078Ah ; reserved for future use
  100.     dw    0            ; 0078Bh ; reserved for future use
  101.         dw      offset _audiomixr       ; 00B88h ; Audio Mixer Control Register
  102.     dw    offset _intrctlrst    ; 00B89h ; Interrupt Status Register
  103.     dw    offset _audiofilt    ; 00B8Ah ; Audio Filter Control Register
  104.     dw    offset _intrctlr    ; 00B8Bh ; Interrupt Control Register
  105.     dw    offset _pcmdata     ; 00F88h ; PCM data I/O register
  106.         dw      0                       ; 00F89h ; reserved for future use
  107.         dw      offset _crosschannel    ; 00F8Ah ; Cross Channel
  108.     dw    0            ; 00F8Bh ; reserved for future use
  109.         dw      offset _samplerate      ; 01388h ; Sample Rate Timer Register
  110.     dw    offset _samplecnt    ; 01389h ; Sample Count Register
  111.     dw    offset _spkrtmr     ; 0138Ah ; Local Speaker Timer Address
  112.     dw    offset _tmrctlr     ; 0138Bh ; Local Timer Control Register
  113.     dw    offset _mdirqvect    ; 01788H ; MIDI IRQ Vector Register
  114.     dw    offset _mdsysctlr    ; 01789H ; MIDI System Control Register
  115.     dw    offset _mdsysstat    ; 0178AH ; MIDI IRQ Status Register
  116.     dw    offset _mdirqclr    ; 0178BH ; MIDI IRQ Clear Register
  117.     dw    offset _mdgroup1    ; 01B88H ; MIDI Group #4 Register
  118.     dw    offset _mdgroup2    ; 01B89H ; MIDI Group #5 Register
  119.     dw    offset _mdgroup3    ; 01B8AH ; MIDI Group #6 Register
  120.     dw    offset _mdgroup4    ; 01B8BH ; MIDI Group #7 Register
  121.  
  122.     extrn    mvhwShadowPointer    :dword
  123.     extrn    _MVTranslateCode    :word     ; hardware I/O offset
  124.     extrn    _MVHWVersionBits    :word     ; hardware bits
  125.  
  126. ;
  127. ;---------------------------========================---------------------------
  128. ;---------------------------====< CODE SECTION >====---------------------------
  129. ;---------------------------========================---------------------------
  130. ;
  131.     .code
  132.  
  133. ;
  134. ;   /*\
  135. ;---|*|
  136. ;---|*|---------------====< Prototypes >====---------------
  137. ;---|*|
  138. ;---|*| void MVOut( int, int, int )
  139. ;---|*|
  140. ;---|*| Output a masked byte directly to the hardware, and return the new value
  141. ;---|*|
  142. ;---|*| Entry Conditions:
  143. ;---|*|     wParm1 is the port address
  144. ;---|*|     wParm2 is the and mask of bits to be written
  145. ;---|*|     wParm3 is the xor data to be written
  146. ;---|*|
  147. ;---|*| Exit Conditions:
  148. ;---|*|     if wParm2 = 0,  al = read from hardware, ah = shadowed data
  149. ;---|*|     if wParm2 = !0, value is written to the hardware & shadow table
  150. ;   \*/
  151. ;
  152.     public    MVOut
  153. MVOut   PROC
  154.     push    bp
  155.     mov    bp,sp
  156. ;
  157. ; this code can only be processed once per loading
  158. ;
  159.     cmp    [invmso_first],-1    ; have we been here?
  160.     jnz    @F            ; yes, don't do this again
  161.     mov    [invmso_first],0    ; no, so pass by just once
  162.     call    __initmvout
  163.     call    MVInitStatePtr        ; initialize the state table
  164.     @@:
  165. ;
  166. ; perform the read from the state table, or write to the hardware
  167. ;
  168.         push    es
  169.  
  170.     mov    dx,wParm1        ; port address
  171.  
  172.     call    _getregisterptr     ; get the shadow hardware register ptr
  173.         jc      mvout_exit              ; IO address not found
  174.  
  175.     mov    cx,wParm2        ; mask
  176.         mov     ax,wParm3               ; data
  177.  
  178.     jcxz    mvout_read        ; read request, just return the data
  179.  
  180.     and    al,cl            ; merge new and old bits
  181.     not    cl            ; get the other bits
  182.     and    cl,es:[bx]        ; from the shadow state
  183.     or    al,cl            ; and merge them in
  184.     xor    dx,[_MVTranslateCode]    ; xlate the board address
  185.     out    dx,al            ; output to the hardware
  186.     mov    es:[bx],al        ; save the new state
  187. ;
  188. mvout_exit:
  189.     pop    es
  190.     pop    bp
  191.     ret
  192. ;
  193. mvout_read:
  194.     mov    al,es:[bx]        ; gets the value from the state table
  195.     jmp    short mvout_exit
  196.  
  197. MVOut    endp
  198.  
  199. ;
  200. ;   /*\
  201. ;---|*|---------------====< __initmvout() >====---------------
  202. ;---|*|
  203. ;---|*| Initializes this body of code. It will try to find the int 2F DOS
  204. ;---|*| interface to the MVPROAS device. Once found, the new state table
  205. ;---|*| pointer will be loaded.
  206. ;---|*|
  207. ;---|*| Entry Conditions:
  208. ;---|*|     None
  209. ;---|*|
  210. ;---|*| Exit Conditions:
  211. ;---|*|     DX:AX point to the state table
  212. ;   \*/
  213.  
  214. __initmvout    proc    near
  215.     push    es
  216.     push    di
  217.     mov    ax,ds
  218.     mov    es,ax
  219. ;
  220. ; adjust the shadow data table offsets to the correct linked offset
  221. ;
  222.     mov    cx,SHADOWTABLELEN    ; table length...
  223.         lea     bx,FirstDataByte        ; the compiled offsets must be adjusted
  224.     lea    di,shadowdatatable    ; DI points to the table
  225.     ;
  226.     @@:
  227.     add    es:[di],bx        ; move the offsets in the table
  228.     inc    di
  229.         inc     di
  230.     loop    @B
  231.  
  232.     cmp    [_MVHWVersionBits],-1    ; already found?
  233.     jnz    inmv_done        ; yes, continue on..
  234.  
  235.     mov    ax,USE_ACTIVE_ADDR    ; defaults to the original address
  236.     push    ax
  237.     call    mvGetHWVersion        ; find the board address...
  238.     add    sp,2
  239. ;
  240. inmv_done:
  241.         pop     di
  242.     pop    es
  243.     ret
  244.  
  245. __initmvout    endp
  246.  
  247. ;
  248. ;---------------------====< _getregisterptr >====---------------
  249. ;
  250. ; Get a pointer to the state table
  251. ;
  252. ; Entry Conditions:
  253. ;     DX holds the port address
  254. ;
  255. ; Exit Conditions:
  256. ;     ES:BX holds the pointer, no other registers modified
  257. ;
  258. _getregisterptr proc    near
  259.     push    di            ; no toucha dees...
  260.     push    cx
  261.  
  262.     mov    cx,ds
  263.     mov    es,cx
  264.     lea    di,shadowregtable    ; look in the register table
  265.     mov    cx,SHADOWTABLELEN
  266.  
  267.     xchg    ax,dx            ; ax holds the port address
  268.     cld
  269.     repne    scasw
  270.     xchg    ax,dx            ; restore 'em...
  271.  
  272.     stc                ; just in case we bomb out
  273.         jne     @F                      ; no match, bomb out...
  274.  
  275. if MODELSIZE eq 0
  276.     assume    es:@code        ; tiny (.com) model is same as code
  277. else
  278.     assume    es:@data        ; all other has a data segment
  279. endif
  280.  
  281.         sub     di,offset shadowregtable+2 ; create an offset into the table
  282.     mov    bx,es:[shadowdatatable+di] ; bx = the offset from the 1st ptr
  283.     mov    di,es:[shadowdatatable+0]  ; grab the first ptr
  284.     sub    bx,di               ; bx holds a zero based offset
  285.     les    di,mvhwShadowPointer       ; get the true state table pointer
  286.     add    bx,di               ; bx now points into the true table
  287.         assume  es:nothing
  288.  
  289.     clc                ; was found, indicate so...
  290. ;
  291. @@:
  292.     pop    cx
  293.     pop    di
  294.         ret
  295.  
  296. _getregisterptr endp
  297.  
  298. ;   /*\
  299. ;---|*| end of MVOut
  300. ;   \*/
  301.  
  302.         end
  303.  
  304.